"""
@name : 高阶函数
@author : shiyaling
@projectname : xsfh
"""
# 利用map批量检测用户名是否符合规范=> username符合规范, username不符合规范
# 只能包含数据、字母、下划线，不以数字开头，长度在6-18之间
# filter把合法的用户名显示出来
# import re
# def func(u):
#     a = 0
#     if re.findall(r"[a-zA-Z_][a-zA-Z0-9_]{5,17}",u) == [u]:
#         return f"{u}符合规范"
#     else:
#         return f"{u}不符合规范"
#
# username =["abcdefes","asdrerdf","3sdfae","sdf","s_32fweer3","_aser3242"]
# result = map(func,username)
# print(list(result))
#
# result = filter(lambda u:re.findall(r"[a-zA-Z_][a-zA-Z0-9_]{5,17}",u) == [u],username)
# print("符合规范的有：")
# print(list(result))



# 匿名函数+reduce实现 1*2*3*...*n
# from functools import reduce
# print(reduce(lambda x,y:x*y,range(1,n+1)))



# filter函数:找出[1-100]能被3整除的数
# print(list(filter(lambda x:x % 3 == 0,range(1,101))))



# map函数:求list[1-10]各项的平方
# lst = [1,2,3,4,5,6,7,8,9,10]
# print(list(map(lambda x:x*x,lst)))



# 将列表[1,4,5,9] 转换成 '1459'的字符串
from functools import reduce
# lst = [1,4,5,9]
# print(reduce(lambda x,y:x*10+y,lst))



# 有以下列表：list1=[7, -8, 5, 4, 0, -2, -5]
# 正数在前负数在后
# 整数从小到大
# 负数从大到小

# list1 = [7,8,5,4,0,-2,-5]
# list2 = []
# list3 = []
# for i in list1:
#     if i > 0:
#         list2.append(i)
#     else:
#         list3.append(i)
# lst2 = sorted(list2,)
# lst3 = sorted(list3,reverse=True)
# lst = lst2 + lst3
# print(lst)



# 这是一个字符串排序，排序规则：小写<大写<奇数<偶数
# s = 'asdf234GDSdsf23' #排序:小写-大写-奇数-偶数
# 原理：先比较元组的第一个值，FALSE

# s = 'asdf234GDSdsf23'
# lst = []
# for i in s:
#     if i.isdigit() == True:
#         if int(i) % 2 == 0:
#             lst.append((False,i))
#     else:
#         lst.append((True,i))
# lst1 = sorted(lst,reverse=True)
# lst2 = []
# for i in lst1:
#     lst2.append(i[1])
# print(lst2)





